package com.ibm.risk.irmp.common.config.redis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;

@Slf4j
@Configuration
@ConditionalOnProperty(value = "spring.data.redis.mode", havingValue = "standalone", matchIfMissing = false)
public class RedisStandaloneConfig {

    @Bean
    public RedisStandaloneConfiguration redisStandaloneConfiguration(RedisProperties prop) {
        log.info("Redis in standalone mode: {}:{}", prop.getHost(), prop.getPort());
        RedisStandaloneConfiguration conf = new RedisStandaloneConfiguration();
        BeanUtils.copyProperties(prop, conf);
        return conf;
    }
}
